package com.example.helloworld;

import com.example.helloworld.tools.Tools;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class ItemDescriptionActivity extends Activity {

	private Context context;
	
	private EditText itemDetails;
	private TextView headerText;
	private ImageView itemImage;
	private ImageView headerImage;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.description_of_item);
		
		context = this.getApplicationContext();
		
		mapUI();

		bindData();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}
	
	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		
	}

	private void mapUI() {
		itemDetails = (EditText)findViewById(R.id.item_details);
		headerText = (TextView)findViewById(R.id.text_header);
		headerText.setText(getString(R.string.item_description_name));
		itemImage = (ImageView)findViewById(R.id.item_image);
		headerImage = (ImageView)findViewById(R.id.image_of_header);
		
		headerImage.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent = new Intent(context, MainActivity.class);
				startActivity(intent);
				Tools.print(getClass() + "onDestroy");
			}
		});
		
	}
	
	private void bindData() {
		int imageId = getIntent().getIntExtra(getString(R.string.item_object_image_id), R.drawable.ic_launcher);
		String data = getIntent().getStringExtra(getString(R.string.item_object_data));
		itemDetails.setText(data);
		itemImage.setImageResource(imageId);
	}
	
}
